﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Content;

public enum VideoKind
{
    INTROVIDEO
}

class VideoScreen : GameScreen
{
    Video video;
    VideoPlayer vidPlayer;

    VideoKind videoKind;

    double timer;

    string videoName;

    public VideoScreen(string videoName, VideoKind kind)
    {
        videoKind = kind;
        this.videoName = videoName;
        timer = 0;
    }

    public override void LoadContent()
    {
        ContentManager content = ScreenManager.Game.Content;
        video = content.Load<Video>(videoName);
        vidPlayer = new VideoPlayer();
        vidPlayer.Play(video); 
    }

    public override void HandleInput()
    {
        if (InputManager.IsActionTriggered(InputManager.Action.Back))
        {
            EndVideo();
            return;
        }

        base.HandleInput();
    }

    public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
    {
        timer += gameTime.ElapsedGameTime.TotalSeconds;

        if (timer > video.Duration.TotalSeconds)
        {
            EndVideo();
        }
    }

    public void EndVideo()
    {
        if(videoKind == VideoKind.INTROVIDEO)
            ScreenManager.AddScreen(new MainMenuScreen());
        ExitScreen();
    }

    public override void Draw(GameTime gameTime)  
    {
        SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

        spriteBatch.Begin();
        
        spriteBatch.Draw(vidPlayer.GetTexture(), new Vector2(200,0), null, Color.White, 0, new Vector2(0,0), 3, SpriteEffects.None, 0);

        spriteBatch.End();
    }  

}
